<template>
	<view class="cu-list menu sm-border resume-list">
		<view class="cu-item resume-item" v-for="(resume,index) in resumeData" :key="index">
			<view class="file-icon">
				<text class="iconfont icon-resume-line margin-right-xs file-icon-info"></text>
			</view>
			<view class="content  resume-content" @tap="goMyInfo(resume._id)">
				<view class="resume-info-one">
					<view class="resume-title">{{resume.resume_name}}</view>
					<text class="iconfont icon-gengduo margin-right-xs .resume-gengduo"
						@tap.stop="resumeClickHanle(resume._id)"></text>
				</view>
				<view class="resume-info-two">
					<view class="resume-position">{{resume.expected_position}}</view>
					<view class="resume-time">{{resume.updata_time}}</view>
				</view>
			</view>
		</view>
		<view class="cu-modal" :class="showRemoveName?'show':''" @click.self="hideRemoveNameModal">
			<view class="cu-dialog bg-white" @click.stop>
				<view class="cu-bar  justify-end">
					<view class="content">修改简历名称</view>
					<view class="action" @tap="hideRemoveNameModal">
						<text class="cuIcon-close"></text>
					</view>
				</view>
				<view class="padding-xl content-input">
					<view class="cu-form-group">
						<input placeholder="输入简历名称" name="input" v-model="changeRemoveName"></input>
					</view>
				</view>
				<view class="cu-bar justify-end">
					<view class="save-name" @tap="saveRemoveName">保存</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showRemoveName: false,
				changeRemoveName: '',
				changeRemoveId: -1
			};
		},
		props: {
			resumeData: {
				type: Array,
				default: []
			}
		},
		methods: {
			resumeClickHanle(resumeId) {
				wx.showActionSheet({
					itemList: ['编辑简历', '删除简历', '重命名简历'],
					success: (res) => {
						let {
							tapIndex
						} = res;
						switch (tapIndex) {
							case 0:
								this.$comm.navigateTo(`/pages/my-info/my-info?resumeId=${resumeId}`)
								break;
							case 1:
								wx.showModal({
									title: ' 温馨提示',
									content: '确认要删除简历么',
									success: (res) => {
										if (res.confirm) {
											this.$api.delResume({
												_id: resumeId
											}).then(res => {
												if (res.code) {
													this.$comm.successToShow("删除成功",
														() => {
															this.$store.commit(
																'resume/delResumeByIdData', {
																	_id: resumeId
																})
														})
												}
											})
										}
									}
								})
								break;
							case 2:
								let resume = this.resumeData.find(resume => resume._id === resumeId)
								this.changeRemoveName = resume.resume_name
								this.changeRemoveId = resume._id
								this.showRemoveNameModal()
								break;
							default:
								break;
						}
					}
				})
			},
			goMyInfo(resumeId) {
				this.$comm.navigateTo(`/pages/my-info/my-info?resumeId=${resumeId}`)
			},
			hideRemoveNameModal() {
				this.showRemoveName = false
			},
			showRemoveNameModal() {
				this.showRemoveName = true
			},
			saveRemoveName() {
				this.hideRemoveNameModal()
				this.$api.updateResume({
					_id: this.changeRemoveId,
					resume_name: this.changeRemoveName
				}).then(res => {
					if (res.code) {
						this.$store.commit('resume/updateResumeName', {
							_id: this.changeRemoveId,
							resume_name: this.changeRemoveName
						})
						this.$comm.successToShow("修改成功")
						// this.$root.loadResumeList().then(() => {})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.cu-list.resume-list {
		.cu-item.resume-item {
			display: flex;
			background-color: transparent;
			padding-top: 40upx;
			padding-bottom: 40upx;
			padding-left: 40upx;
			padding-right: 40upx;

			&:nth-last-child(2)::after {
				border: none;
			}

			&::after {

				border-bottom: 5upx solid $border-cBBB;
			}

			.file-icon {
				margin-right: 20upx;
				height: 100%;

				align-self: flex-start;

				.file-icon-info {
					font-size: 60upx;
					color: $font-icon;
				}
			}

			.resume-content {
				display: flex;
				flex-direction: column;

				.resume-info-one,
				.resume-info-two {
					display: flex;
					align-items: center;

				}

				.resume-info-one {
					.resume-title {
						color: $font-c10;
						font-size: 32upx;
						flex: 1;
					}

					.resume-gengduo {
						font-size: 40upx;
						color: $font-icon;
					}
				}


				.resume-info-two {
					padding: 12upx 0upx 0upx;

					.resume-position {
						color: $font-cA7;
						font-size: 26upx;
						flex: 1;
					}

					.resume-time {
						color: $font-cA7;
						font-size: 26upx;
					}
				}
			}
		}

		.cu-modal {
			z-index: 9999;
		}

		.cu-dialog {
			width: 640upx;
			border-radius: 25upx;

			.content-input {
				padding: 0upx 50upx 20upx;
			}

			.cu-form-group input {
				font-size: 36upx;
			}

			.save-name {
				width: 100%;
				height: 100%;
				border: none;
				border-top: 1upx solid $index-bgEE;
				margin: 0upx;
				display: flex;
				justify-content: center;
				align-items: center;
				min-height: 100rpx;
				color: $index-color;
				font-size: 34upx;
			}
		}

	}
</style>
